<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\model;

use app\common\model\store\IndexBanner as IndexBannerModel;
use app\common\model\UploadFile as UploadFileModel;
use think\model\relation\HasOne;
use app\api\model\{Goods as GoodsModel};
/**
 * 商家记录表模型
 * Class Store
 * @package app\store\model
 */
class IndexBanner extends IndexBannerModel
{
    /**
     * 隐藏的字段
     * @var string[]
     */
    protected $hidden = [
        'sort',
        'is_delete',
        'create_time',
        'update_time'
    ];

    /**
     * 关联logo图片
     * @return HasOne
     */
    public function logoImage(): HasOne
    {
        return $this->hasOne('UploadFile', 'file_id', 'image_id')
            ->bind(['image_url' => 'preview_url']);
    }

    /**
     * 获取当前商城的基本信息
     * @return Store|array|null
     */
    public static function getInfo()
    {
        return static::detail(static::$storeId);
    }

    


      /**
     * 获取列表
     * @param array $param
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getIndeBannerList($type_id,$second_type_id,$store_id){
            // 商品详情
            $model = new GoodsModel;
        $list = $this->where('type_id', '=', $type_id)
           ->where('second_type_id', '=', $second_type_id)
            ->where('store_id', '=', $store_id)
            ->where('is_delete', '=', 0)
            ->order(['sort', $this->getPk()])
            ->select();
        foreach($list as $k=>$v){
            if($v['image_id']){
                $img = UploadFileModel::detail($v['image_id']);
                // $list[$k]['image'] = $img;
                $list[$k]['image_url'] = $img['preview_url'];
            }else{
                // $list[$k]['image'] = array();
                $list[$k]['image_url'] = '';
            }
            if($v['goods_id']){
                 $goodsInfo = $model->getDetails($v['goods_id']);
                //  var_dump($goodsInfo->toArray());
                //  var_dump($goodsInfo->goods_price_old_min);
                 $list[$k]['goods_price']=  $goodsInfo->goods_price_old_min;
            }else{
                $list[$k]['goods_price']= '';
            }
        }

        return $list;

    }

}
